Lifecycle: Lifecycle Control

更新时间:
2024-05-17
下载文档

Lifecycle: Lifecycle Control

EdgerOS provides app lifecycle function, developers can use these APIs for app lifecycle management.

Functions

edger.lifecycle.init()

This method should be called when app is in initialization state.

edger.lifecycle.ready()

This method should be called when app is in ready state, and the system will turn off the splash.

edger.lifecycle.reload()

This method should be called when app key resources load fail, the system give a chance to reload the resources again.

Example

const edger = window.edger;

// The init method must be called as earlier as possiable.
edger.lifecycle.init();

function isImportantResourceError(e) {
  // Failed to load resources that affect functionality.
  ...
}

// If some key resources loaded fail, the API can be called to reload the app.
window.addEventListener('error', (e) => {
  if (isImportantResourceError(e)) {
    edger.lifecycle.reload();
  }
})

function firstScreenReady() {
  ...
}

window.addEventListener('load', (e) => {
  if (firstScreenReady()) {
    edger.lifecycle.ready();
  }
})
文档内容是否对您有所帮助?
有帮助
没帮助